/*合作信息*/
//获取财务信息
var getCooperationDetail = getCooperationDetailPro(thisProviderId);

/*详情信息渲染*/
getCooperationDetail.then(
    (res) => {
        if (res){
            renderForm(res);
        }
    },  // 成功
    (err) => {console.log(err)} // 失败
)

function formatProviderType(providerType) {
    if (!providerType) {
        return '';
    }
    var channelDesc = '';
    switch (providerType) {
        case 10:
            channelDesc = '专项服务商';
            break;
        case 20:
            channelDesc = '赋能服务商';
            break;
        default:
            channelDesc = providerType;
            break;
    }
    return channelDesc;
}

function showDialog (data) {
    var str = '';
    data.forEach((item) => {
        str += '<span>'+item.name+'</span> '
    })
    layer.alert(str, {title:'服务区域',offset:'c'})
}

function formatSaleAreas(saleAreas) {
    var areaHtml = '';
    saleAreas && saleAreas.forEach((item) => {
        if (item.code == 0) {
            areaHtml += '<div class="customer-item">'+
                '<span>'+item.name+'</span>'+
            '</div>'
        } else {
            areaHtml += '<div class="customer-item">'+
                '<span>'+item.name+'</span> '+
                "<a onclick='showDialog("+JSON.stringify(item.children)+")'>("+item.children.length+")</a>"
            +'</div>'
        }
    })
    return areaHtml;
}

function formatCustomerNameList (data) {
    var customer ='';
    data && data.forEach((item) => {
        customer += '<div class="customer-item-name" title="'+item.customerName+'">'+item.customerName+'</div>'
    })
    return customer;
}

function formatCustomerNumList (data) {
    var customer ='';
    data && data.forEach((item) => {
        customer += '<div class="customer-item" title="'+item.customerNumber+'">'+item.customerNumber+'</div>'
    })
    return customer;
}


function renderForm(res){
    var cooperationHtml = "";
    res.forEach((item,index) => {
        cooperationHtml += '<tr class="text-c">\n' +
            // '        <td>'+(index+1)+'</td>\n' +
            '        <td title="'+item.channelNumber+'">'+item.channelNumber+'</td>\n' +
            '        <td title="'+item.channelName+'">'+item.channelName+'</td>\n' +

            // '        <td>'+formatCustomerNumList(item.customerList)+'</td>\n' +
            '        <td>'+formatCustomerNameList(item.customerList)+'</td>\n' +

            '        <td title="'+dealNull(item.rate)+'%">'+dealNull(item.rate)+'%</td>\n' +
            '        <td title="'+formatProviderType(item.providerType)+'">'+formatProviderType(item.providerType)+'</td>\n' +
            '        <td>'+formatSaleAreas(item.saleAreas)+'</td>\n' +
            '    </tr>';
    });
    $("#cooperation-table tbody").html(cooperationHtml);
};